package org.example.lotterysystem.controller;

import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.example.lotterysystem.common.domain.Result;
import org.example.lotterysystem.common.domain.dto.ShortMessageLoginDTO;
import org.example.lotterysystem.common.domain.dto.UserPasswordLoginDTO;
import org.example.lotterysystem.common.domain.dto.UserRegisterDTO;
import org.example.lotterysystem.common.domain.vo.BaseUserInfoVO;
import org.example.lotterysystem.common.domain.vo.UserLoginVO;
import org.example.lotterysystem.common.domain.vo.UserRegisterVO;
import org.example.lotterysystem.service.UserService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
public class UserController {

    @Resource
    public UserService userService;

    /**
     *用户注册
     */
    @PostMapping("/register")
    public Result<UserRegisterVO> register(@Validated @RequestBody UserRegisterDTO userRegisterDTO){
        log.info("register方法请求参数:{}",userRegisterDTO.toString());
        return Result.success(userService.register(userRegisterDTO));
    }

    /**
     * 发送验证码
     */
    @RequestMapping("/verification-code/send")
    public Result<Boolean> sendVerificationCode(String phoneNumber){
        return Result.success(userService.send(phoneNumber));
    }

    /**
     *密码登录
     */
    @RequestMapping("/password/login")
    public Result<UserLoginVO> userPasswordLogin(
            @Validated @RequestBody UserPasswordLoginDTO userPasswordLoginDTO){
        return Result.success(userService.userPasswordLogin(userPasswordLoginDTO));
    }

    /**
     * 验证码登录
     */
    @RequestMapping("/message/login")
    public Result<UserLoginVO> shortMessageLogin(
            @Validated @RequestBody ShortMessageLoginDTO shortMessageLoginDTO){
        return Result.success(userService.shortMessageLogin(shortMessageLoginDTO));
    }

    /**
     * 根据身份获取人员列表
     */
    @RequestMapping("/base-user/find-list")
    public Result<List<BaseUserInfoVO>> findBaseUserInfo(String identity){
        return Result.success(userService.findBaseUserInfo(identity));
    }

}
